package com.video.user.controller;


import com.video.common.result.ResponseResult;
import com.video.common.utils.UserContext;
import com.video.user.domain.entity.CollectUser;
import com.video.user.service.ICollectUserService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

import static com.alibaba.nacos.api.cmdb.pojo.PreservedEntityTypes.service;

/**
 * <p>
 * 收藏表 前端控制器
 * </p>
 *
 * @author la
 * @since 2024-11-18
 */
@RestController
@RequestMapping("/collect-user")
@RequiredArgsConstructor
public class CollectUserController {


    private final ICollectUserService service;
    /*
     * 查询用户是否点赞过该视频
     * */
    @GetMapping("/queryCollect")
    public ResponseResult queryLike(Long videoId) {
        Long user = UserContext.getUser();
        // 查询数据是否存在
        Long count = service.lambdaQuery()
                .eq(videoId != null, CollectUser::getVideoId, videoId)
                .eq(user != null, CollectUser::getUserId, user)
                .count();

        Map<String, Object> map = new HashMap<>();
        // 判断是否存在
        if (count > 0) {
            map.put("isCollect", true);
        } else {
            map.put("isCollect", false);
        }
        return ResponseResult.okResult(map);
    }
}
